package com.jdh.fileUpload.controller;

import com.jdh.fileUpload.service.fileUpload.FileUploadMinioService;
import com.jdh.fileUpload.service.fileUpload.FileUploadService;
import com.jdh.fileUpload.utils.Result;
import com.jdh.fileUpload.vo.DiskFileIndexVo;
import com.jdh.fileUpload.vo.PartFileIndexVo;
import com.jdh.fileUpload.vo.PointFileIndexVo;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: FileUploadController
 * @Author: jdh
 * @CreateTime: 2022-03-15
 * @Description:
 */
@Slf4j
@RestController
@RequestMapping("/minio")
@CrossOrigin("*")
@ConditionalOnProperty(prefix = "autoconfigure", value = "isMinio", matchIfMissing = false)
public class MinioFileUploadController {

    @Autowired
    private FileUploadMinioService fileUploadMinioService;

    /**
     * 单文件上传
     *
     * @param file
     */
    @PostMapping("/singleFileUploadMinio")
    public Result<Boolean> singleFileUploadMinio(@RequestParam("file") MultipartFile file) {
        log.info("minio单文件上传操作,文件大小为:{}", file.getSize());
        Result<Boolean> result = fileUploadMinioService.fileUploadMinio(file);
        return result;
    }

    /**
     * 文件分片上传
     *
     * @param file
     */
    @PostMapping("/partFileUploadMinio")
    public Result<Boolean> partFileUploadMinio(@RequestParam("file") MultipartFile file, @RequestParam("partFileIndex") String partFileIndexVo) {
        log.info("minio文件分片上传操作,文件大小为:{}", partFileIndexVo);
        Result<Boolean> result = fileUploadMinioService.filePartUploadMinio(file, partFileIndexVo);
        return result;
    }

    /**
     * 测试接口
     */
    @PostMapping("/fileTest")
    public Result<String> fileTest() {
        log.info("测试接口");
        return Result.success("测试通过");
    }
}
